# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gtk3

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.12.2
pkgrel=1
pkgdesc="GObject-based multi-platform GUI toolkit (v3) (mingw-w64)"
arch=('any')
url="http://www.gtk.org"
license=("LGPL")
install=gtk3-${CARCH}.install
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-python2"
    "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
# python2 is required to run gdbus-codegen
makedepends+=("autoconf" "automake" "libtool")
# autotools are required because several Makefile.am are modified
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-atk>=2.7.5"
    "${MINGW_PACKAGE_PREFIX}-pango>=1.32.4"
    "${MINGW_PACKAGE_PREFIX}-glib2>=2.37.5"
    "${MINGW_PACKAGE_PREFIX}-cairo>=1.12.0"
    "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2>=2.27.1"
    "${MINGW_PACKAGE_PREFIX}-shared-mime-info")
options=('strip' 'staticlibs')
source=("http://ftp.gnome.org/pub/gnome/sources/gtk+/${pkgver%.*}/gtk+-${pkgver}.tar.xz"
    0001-REBURN-THE-DEF-FILE.mingw.patch
    0010-put-gtk-dll-into-path.mingw.patch
    0012-embed-manifest.all.patch
    0014-fix-gnu-print-format.patch
    0015-Suppress-a-warning-from-SetWindowLongPtr.all.patch)
md5sums=('0d6d8f9f79132b3b47475d047b369b1c'
         '53ddd35c66dafd59567c4babf79d2821'
         '9e0296da2986be7697cf343563b85d1f'
         '47aa5b0d120102d526d2f781338f93b1'
         '3052a2c4dac22042780471b14463ea89'
         '36ad8b20dd38e586e92ddb39c59eb923')

prepare() {
  cd "${srcdir}/gtk+-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-REBURN-THE-DEF-FILE.mingw.patch"
  patch -Np1 -i "${srcdir}/0010-put-gtk-dll-into-path.mingw.patch"
  patch -Np1 -i "${srcdir}/0012-embed-manifest.all.patch"
  patch -Np1 -i "${srcdir}/0014-fix-gnu-print-format.patch"
  patch -Np1 -i "${srcdir}/0015-Suppress-a-warning-from-SetWindowLongPtr.all.patch"
  autoreconf -i
}

build() {
  export MSYS2_ARG_CONV_EXCL="-//OASIS"
  CFLAGS+=" -mms-bitfields"
  CXXFLAGS=" -mms-bitfields"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ${srcdir}/gtk+-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-win32-backend \
    --disable-gtk2-dependency \
    --enable-static \
    --enable-shared \
    --enable-introspection \
    --disable-cups
  make
}

package() {
  export MSYS2_ARG_CONV_EXCL="-//OASIS"
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' -o -name '*.manifest' | xargs -rtl1 rm
  
  mv ${pkgdir}${MINGW_PREFIX}/bin/gtk-update-icon-cache{,-3.0}.exe
  mv ${pkgdir}${MINGW_PREFIX}/share/man/man1/gtk-update-icon-cache{,-3.0}.1
}
